package sz.com.postoffice.jxyzwgcase.controller;

import com.sun.istack.NotNull;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import sz.com.postoffice.jxyzwgcase.core.TableDataInfo;
import sz.com.postoffice.jxyzwgcase.pojo.GridModel;
import sz.com.postoffice.jxyzwgcase.service.GridModelService;

import javax.annotation.Resource;

/**
 * @ClassName ResourceController
 * @Deacription
 * @Author jmx
 * @Date 2020/11/20 19:52
 * @Version 1.0
 **/
@Api(value = "网格基础信息", tags = "{网格基础信息API}")
@RestController
@Slf4j
@RequestMapping(value = "/resource")
public class GridModelController {
    @Resource
    private GridModelService gridModelService;

    @ApiOperation(value = "新增网格", notes = "新增网格")
    @RequestMapping(value = "/grids", method = RequestMethod.POST)
    public boolean insert(@RequestBody GridModel grid) {
        System.out.println("开始新增...");
        return gridModelService.insert(grid);
    }

    @ApiOperation(value = "修改网格", notes = "修改网格")
    @RequestMapping(value = "/grids", method = RequestMethod.PUT)
    public boolean update(@RequestBody GridModel grid) {
        System.out.println("开始修改...");
        return gridModelService.update(grid);
    }

    @ApiOperation(value = "根据id查询网格详情", notes = "根据id查询网格详情")
    @RequestMapping(value = "/grids/{id}", method = RequestMethod.GET)
    public GridModel findById(@PathVariable("id") @NotNull @ApiParam(name="网格id",value="path传入",required=true) Integer id) {
        System.out.println("开始查询...");
        return gridModelService.findByPrimaryKey(id);
    }

    @ApiOperation(value = "查询网格列表", notes = "查询网格列表")
    @RequestMapping(value = "/grids", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", dataType = "int", paramType = "path", required = true),
            @ApiImplicitParam(name = "pageNum", value = "当前页", dataType = "int", paramType = "path", required = true)
    })
    public TableDataInfo findListByEntity(GridModel grid) {
        System.out.println("开始查询...");
        return gridModelService.findByListEntity(grid);
    }
}
